package top.scsoul.pas.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Entity
@Table(name = "sys_user")
public class User implements Serializable {
    @Transient
    private static final long serialVersionUID = 187465132L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id")
    private Long id;
    @Column(name = "user_name")
    private String name;
    @Length(max = 15)
    @Column(name = "user_login_name", length = 15, unique = true)
    private String loginName;
    @Column(name = "user_password")
    private String password;
    @Column(name = "user_last_login")
    private Date lastLoginTime;
    @Column(name = "user_created")
    private Date created;
    @Column(name = "user_state")
    private Integer state;
    @ManyToMany(targetEntity = Role.class,fetch = FetchType.EAGER)
    @JoinTable(
            name = "sys_user_role",
            joinColumns = {@JoinColumn(name = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")}
    )
    private List<Role> roles;
}
